package com.smartleanx.module.hrm.controller.admin.employee;

import com.smartleanx.module.hrm.controller.admin.employee.work.EmployeeWorkExperienceRespVO;
import com.smartleanx.module.hrm.controller.admin.employee.work.EmployeeWorkExperienceSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.module.hrm.dal.dataobject.employee.EmployeeWorkExperienceDO;
import com.smartleanx.module.hrm.service.employee.EmployeeWorkExperienceService;

@Tag(name = "管理后台 - 员工工作经历")
@RestController
@RequestMapping("/hrm/employee-work-experience")
@Validated
public class EmployeeWorkExperienceController {

    @Resource
    private EmployeeWorkExperienceService employeeWorkExperienceService;

    @PostMapping("/create")
    @Operation(summary = "创建员工工作经历")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-work-experience:create','hrm:employee:update')")
    public CommonResult<Long> createEmployeeWorkExperience(@Valid @RequestBody EmployeeWorkExperienceSaveReqVO createReqVO) {
        return success(employeeWorkExperienceService.createEmployeeWorkExperience(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新员工工作经历")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-work-experience:update','hrm:employee:update')")
    public CommonResult<Boolean> updateEmployeeWorkExperience(@Valid @RequestBody EmployeeWorkExperienceSaveReqVO updateReqVO) {
        employeeWorkExperienceService.updateEmployeeWorkExperience(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除员工工作经历")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-work-experience:delete','hrm:employee:update')")
    public CommonResult<Boolean> deleteEmployeeWorkExperience(@RequestParam("id") Long id) {
        employeeWorkExperienceService.deleteEmployeeWorkExperience(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工工作经历")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-work-experience:query','hrm:employee:query')")
    public CommonResult<EmployeeWorkExperienceRespVO> getEmployeeWorkExperience(@RequestParam("id") Long id) {
        EmployeeWorkExperienceDO employeeWorkExperience = employeeWorkExperienceService.getEmployeeWorkExperience(id);
        return success(BeanUtils.toBean(employeeWorkExperience, EmployeeWorkExperienceRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "根据员工id获得工作经历列表")
    @Parameter(name = "employeeId", description = "员工编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-work-experience:query','hrm:employee:query')")
    public CommonResult<List<EmployeeWorkExperienceRespVO>> getEmployeeWorkExperienceList(@RequestParam("employeeId") Long employeeId) {
        List<EmployeeWorkExperienceDO> workExperienceList = employeeWorkExperienceService.getEmployeeWorkExperienceList(employeeId);
        return success(BeanUtils.toBean(workExperienceList, EmployeeWorkExperienceRespVO.class));
    }

}